﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.ApplicationModel;

namespace System.ApplicationModel.Composition
{
    /// <summary>
    /// Export contract for a View.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
    public sealed class ViewExportAttribute : ExportAttribute
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="System.ApplicationModel.Composition.ViewExportAttribute"/> class.
        /// </summary>
        /// <param name="contractName">The name of the View.</param>
        public ViewExportAttribute(string contractName) : this(contractName, typeof(object), false) { }

        /// <summary>
        /// Initializes a new instance of the <see cref="System.ApplicationModel.Composition.ViewExportAttribute"/> class.
        /// </summary>
        /// <param name="contractName">The name of the View.</param>
        /// <param name="isShell">True if the View must be loaded on application startup ; otherwise false.</param>
        public ViewExportAttribute(string contractName, bool isShell) : this(contractName, typeof(object), isShell) { }

        /// <summary>
        /// Initializes a new instance of the <see cref="System.ApplicationModel.Composition.ViewExportAttribute"/> class.
        /// </summary>
        /// <param name="contractName">The name of the View.</param>
        /// <param name="contractType">The type of the View.</param>
        public ViewExportAttribute(string contractName, Type contractType) : this(contractName, contractType, false) { }

        /// <summary>
        /// Initializes a new instance of the <see cref="System.ApplicationModel.Composition.ViewExportAttribute"/> class.
        /// </summary>
        /// <param name="contractName">The name of the View.</param>
        /// <param name="contractType">The type of the View.</param>
        /// <param name="isShell">True if the View must be loaded on application startup ; otherwise false.</param>
        public ViewExportAttribute(string contractName, Type contractType, bool isShell)
            : base(isShell ? contractName + "ShellView" : contractName + "View", contractType)
        {
            this.IsShell = isShell;
        }

        /// <summary>
        /// Gets a value that indicates if the View must be loaded on application startup.
        /// </summary>
        public bool IsShell { get; private set; }
    }
}
